package com.fly.estore.service.Impl;

import com.fly.estore.dao.MemberLevelDAO;
import com.fly.estore.domain.MemberLevel;
import com.fly.estore.framework.util.CommonUtil;
import com.fly.estore.service.MemberLevelService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Fly on 2016/4/12.
 */
@Service("MemberLevelService")
public class MemberLevelServiceImpl implements MemberLevelService {

    @Autowired
    MemberLevelDAO memberLevelDAO;

    public int saveMemberLevel(MemberLevel memberLevel) {
        int update = 0;
        if (StringUtils.isBlank(memberLevel.getMemberLevelId())){
            //memberLevelId为空，则新增
            memberLevel.setMemberLevelId(CommonUtil.genPK());
            update = memberLevelDAO.addMemberLevel(memberLevel);
        }
        else{
            update = memberLevelDAO.updateMemberLevel(memberLevel);
        }
        return update;
    }

    public int deleteById(String memberLevelId) {
        int update = memberLevelDAO.deleteById(memberLevelId);
        return update;
    }

    public MemberLevel getById(String memberLevelId) {
        MemberLevel memberLevel = null;
        memberLevel = memberLevelDAO.getById(memberLevelId);
        return memberLevel;
    }

    public List<MemberLevel> getMemberLevelList() {
        List<MemberLevel> memberLevelList = new ArrayList<MemberLevel>();
        memberLevelList = memberLevelDAO.getMemberLevelList();
        return memberLevelList;
    }
}
